//
//  MyCourseImgModel.m
//
//  Created by  殷聃 on 2019/8/3
//  Copyright (c) 2019 yek. All rights reserved.
//

#import "MyCourseImgModel.h"


NSString *const kMyCourseImgModelDeviceId = @"deviceId";
NSString *const kMyCourseImgModelUseMood = @"useMood";
NSString *const kMyCourseImgModelUserId = @"userId";
NSString *const kMyCourseImgModelId = @"id";
NSString *const kMyCourseImgModelIsDelete = @"isDelete";
NSString *const kMyCourseImgModelUseTime = @"useTime";
NSString *const kMyCourseImgModelUsePicture = @"usePicture";
NSString *const kMyCourseImgModelUseFeel = @"useFeel";
NSString *const kMyCourseImgModelAddTime = @"addTime";
NSString *const kMyCourseImgModelUseTimeLength = @"useTimeLength";
NSString *const kMyCourseImgModelUseWeight = @"useWeight";


@interface MyCourseImgModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation MyCourseImgModel

@synthesize deviceId = _deviceId;
@synthesize useMood = _useMood;
@synthesize userId = _userId;
@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize isDelete = _isDelete;
@synthesize useTime = _useTime;
@synthesize usePicture = _usePicture;
@synthesize useFeel = _useFeel;
@synthesize addTime = _addTime;
@synthesize useTimeLength = _useTimeLength;
@synthesize useWeight = _useWeight;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.deviceId = [self objectOrNilForKey:kMyCourseImgModelDeviceId fromDictionary:dict];
            self.useMood = [self objectOrNilForKey:kMyCourseImgModelUseMood fromDictionary:dict];
            self.userId = [self objectOrNilForKey:kMyCourseImgModelUserId fromDictionary:dict];
            self.internalBaseClassIdentifier = [self objectOrNilForKey:kMyCourseImgModelId fromDictionary:dict];
            self.isDelete = [self objectOrNilForKey:kMyCourseImgModelIsDelete fromDictionary:dict];
            self.useTime = [self objectOrNilForKey:kMyCourseImgModelUseTime fromDictionary:dict];
            self.usePicture = [self objectOrNilForKey:kMyCourseImgModelUsePicture fromDictionary:dict];
            self.useFeel = [self objectOrNilForKey:kMyCourseImgModelUseFeel fromDictionary:dict];
            self.addTime = [[self objectOrNilForKey:kMyCourseImgModelAddTime fromDictionary:dict] doubleValue];
            self.useTimeLength = [self objectOrNilForKey:kMyCourseImgModelUseTimeLength fromDictionary:dict];
            self.useWeight = [self objectOrNilForKey:kMyCourseImgModelUseWeight fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.deviceId forKey:kMyCourseImgModelDeviceId];
    [mutableDict setValue:self.useMood forKey:kMyCourseImgModelUseMood];
    [mutableDict setValue:self.userId forKey:kMyCourseImgModelUserId];
    [mutableDict setValue:self.internalBaseClassIdentifier forKey:kMyCourseImgModelId];
    [mutableDict setValue:self.isDelete forKey:kMyCourseImgModelIsDelete];
    [mutableDict setValue:self.useTime forKey:kMyCourseImgModelUseTime];
    [mutableDict setValue:self.usePicture forKey:kMyCourseImgModelUsePicture];
    [mutableDict setValue:self.useFeel forKey:kMyCourseImgModelUseFeel];
    [mutableDict setValue:[NSNumber numberWithDouble:self.addTime] forKey:kMyCourseImgModelAddTime];
    [mutableDict setValue:self.useTimeLength forKey:kMyCourseImgModelUseTimeLength];
    [mutableDict setValue:self.useWeight forKey:kMyCourseImgModelUseWeight];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.deviceId = [aDecoder decodeObjectForKey:kMyCourseImgModelDeviceId];
    self.useMood = [aDecoder decodeObjectForKey:kMyCourseImgModelUseMood];
    self.userId = [aDecoder decodeObjectForKey:kMyCourseImgModelUserId];
    self.internalBaseClassIdentifier = [aDecoder decodeObjectForKey:kMyCourseImgModelId];
    self.isDelete = [aDecoder decodeObjectForKey:kMyCourseImgModelIsDelete];
    self.useTime = [aDecoder decodeObjectForKey:kMyCourseImgModelUseTime];
    self.usePicture = [aDecoder decodeObjectForKey:kMyCourseImgModelUsePicture];
    self.useFeel = [aDecoder decodeObjectForKey:kMyCourseImgModelUseFeel];
    self.addTime = [aDecoder decodeDoubleForKey:kMyCourseImgModelAddTime];
    self.useTimeLength = [aDecoder decodeObjectForKey:kMyCourseImgModelUseTimeLength];
    self.useWeight = [aDecoder decodeObjectForKey:kMyCourseImgModelUseWeight];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_deviceId forKey:kMyCourseImgModelDeviceId];
    [aCoder encodeObject:_useMood forKey:kMyCourseImgModelUseMood];
    [aCoder encodeObject:_userId forKey:kMyCourseImgModelUserId];
    [aCoder encodeObject:_internalBaseClassIdentifier forKey:kMyCourseImgModelId];
    [aCoder encodeObject:_isDelete forKey:kMyCourseImgModelIsDelete];
    [aCoder encodeObject:_useTime forKey:kMyCourseImgModelUseTime];
    [aCoder encodeObject:_usePicture forKey:kMyCourseImgModelUsePicture];
    [aCoder encodeObject:_useFeel forKey:kMyCourseImgModelUseFeel];
    [aCoder encodeDouble:_addTime forKey:kMyCourseImgModelAddTime];
    [aCoder encodeObject:_useTimeLength forKey:kMyCourseImgModelUseTimeLength];
    [aCoder encodeObject:_useWeight forKey:kMyCourseImgModelUseWeight];
}

- (id)copyWithZone:(NSZone *)zone
{
    MyCourseImgModel *copy = [[MyCourseImgModel alloc] init];
    
    if (copy) {

        copy.deviceId = [self.deviceId copyWithZone:zone];
        copy.useMood = [self.useMood copyWithZone:zone];
        copy.userId = [self.userId copyWithZone:zone];
        copy.internalBaseClassIdentifier = [self.internalBaseClassIdentifier copyWithZone:zone];
        copy.isDelete = [self.isDelete copyWithZone:zone];
        copy.useTime = [self.useTime copyWithZone:zone];
        copy.usePicture = [self.usePicture copyWithZone:zone];
        copy.useFeel = [self.useFeel copyWithZone:zone];
        copy.addTime = self.addTime;
        copy.useTimeLength = [self.useTimeLength copyWithZone:zone];
        copy.useWeight = [self.useWeight copyWithZone:zone];
    }
    
    return copy;
}


@end
